﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NetCommand
{
    /// <summary>
    /// 网络消息常量码
    /// </summary>
    public class NetCode
    {
        public const UInt16 NO_ERROR            = 0;
        public const UInt16 CRC_ERROR           = 1;
        public const UInt16 DEVICE_WRITE_OK     = 0;
        public const UInt16 DEVICE_WRITE_ERROR  = 1;
        public const UInt16 CMD_TYPE_ERROR      = 2;
        public const UInt16 CMD_FRONT_CODE_ERROR        = 3;
        public const UInt16 CMD_DATA_NULL               = 4;
        public const UInt16 CMD_ERR_TIME_OUT            = 5;
        public const UInt16 CMD_ERROR_DEVICE_OUT_LINE   = 6;
        public const UInt16 CMD_LENGTH_ERROR            = 7;
        public const UInt16 CMD_OK                      = 9;
        public const UInt16 CMD_SUBPACKAGE              = 10;

    }

    public class LoginResult
    {
        public const byte OK = 0;
        public const byte NO_USER = 1;
        public const byte PASSWORD_WRONG = 2;
    }

    public class NetCommon
    {
        // 常亮定义
        public const int Int16Size      = 2;
        public const int Int32Size      = 4;
        public const int CharSize       = 1;
        public const int ByteSize       = 1;
        public const int CRCLength      = 2;
        public const int SpareLength    = 2;
        public const int A_VALVE        = 1;
        public const int B_VALVE        = 2;

        // 读写标记定义
        public const int S2D_READ   = 0x3;
        public const int S2D_WRITE  = 0x6;

        /*
         * 消息头各字段位置
         */
        public const int Index_FRONT_ID     = 0;
        public const int Index_AREA_ID_1    = 1;
        public const int Index_AREA_ID_2    = 2;
        public const int Index_DEVICE_ID    = 3;
        public const int Index_DATA_LEN     = 5;
        public const int Index_CMD_ID_1     = 6;
        public const int Index_CMD_ID_2     = 7;

        // 消息前导码定义
        public const int D2S_HEADER_CODE    = 0xB5;
        public const int S2C_HEADER_CODE    = 0xA5;
        public const int C2S_HEADER_CODE    = 0xC5;
        public const int D2S_TICK_CODE      = 0xF5;

        // 消息类型定义
        public const byte C2S_COMMAND_TYPE = 0;
        public const byte S2C_COMMAND_TYPE = 1;
        public const byte D2S_COMMAND_TYPE = 2;
        public const byte S2D_COMMAND_TYPE = 3;

        public const float OUT_TIME_IN_SEC = 1;
    }
}
